
class SingleInstance():
    """
    这是一个单例类
    """
    obj = None

    def __new__(cls, *args, **kwargs):
        if cls.obj == None:
            cls.obj = super().__new__(cls)
        return cls.obj

    def __init__(self):
        print("这是__init__方法")
        print(self)

    def __str__(self):
        return f"fuck"

    def sing(self):
        """这是唱歌方法"""
        print("sing....")

    def __call__(self, *args, **kwargs):
        print("这是__call__方法")


if __name__ == "__main__":
    singleton1 = SingleInstance()
    singleton2 = SingleInstance()
    print(SingleInstance.__doc__)
    print(SingleInstance.sing.__doc__)
    print(singleton2.__module__)
    print(singleton2.__class__)
    print(singleton2)

    # 判断一个对象是否可调用
    print(callable(SingleInstance))
    print(callable(singleton2))
    singleton2()